<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="keywords" content="">
<meta name="description" content="">
<meta name="renderer" content="webkit">
<meta name="force-rendering" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
<link charset="utf-8" rel="stylesheet" type="text/css" href="/static/ali/ali.css" />
<link charset="utf-8" rel="stylesheet" type="text/css" href="/static/ali/home.css" />
<title>友利钱包账户中心</title>
<style type="text/css">
.layui-input-block{margin-left: 130px;}
.layui-form-radio{width: 110px;}
.layui-form-radio>i:hover, .layui-form-radioed>i {color: #108ee9;}
.layui-form-radio * {font-size: 12px;}
.layui-form-select dl dd.layui-this {background-color: #108ee9;color: #fff;}
.layui-form-label{width: 100px;}
#safe-validate{display: none;padding:16px 16px 0 0;}
#safe-validate .layui-input-block > * {display: inline-block;}
#safe-validate .layui-input-block > input {width: 350px;}
#safe-validate .layui-input-block > a {line-height: 38px;padding:0 8px;}
#description{text-align: center;font-size: 14px;margin-bottom: 14px;color:}
#description>span{margin: 0 4px;}
#description>span.money{font-weight: bold;color: #f4333c;}
</style>
</head>
<body>
	#include("common/header.html", site="home")

	<div class="content">
		<div class="content-wrapper">
			<div class="content-left">
				<div class="menu-title">账户中心</div>
				<div class="menu-group">
					#include("common/sider.html", site="transfer")
				</div>
			</div>
			<div class="content-right">
				<div class="main-title">转账</div>
				<div class="option-panel">
					<div class="tab-container">
						<ul class="nav-tabs">
							<li class="#if(accountType=='bank')active#end"><a href="/customer/home/transfer/bank">转到银行卡</a></li>
							<li class="#if(accountType=='wallet')active#end"><a href="/customer/home/transfer/wallet">转到钱包</a></li>
						</ul>
					</div>
					<form action="" class="layui-form" method="post">
						<div class="form-item">
							<div class="form-label">账号</div>
							<div class="form-value">
								#if(accountType=='wallet')
								<select name="contactsId" lay-ignore required lay-verify="required" lay-verType="tips">
									<option value="">- 请选择 -</option>
									#for(item : walletList)
									<option value="#(item.id)">#(item.contactsShow)</option>
									#end
								</select>
								<a  id="btn-add-wallet">添加钱包好友账户</a>
								#end
								#if(accountType=='bank')
								<select name="contactsId" lay-ignore required lay-verify="required" lay-verType="tips">
									<option value="">- 常用提款账户选择 -</option>
									#for(item : bankCardList)
									<option value="#(item.id)">#(item.contactsShow)</option>
									#end
								</select>
								<a  id="btn-add-bankcard">添加提款账户</a>
								#end
								<a href="/customer/contacts/index">管理</a>
							</div>
						</div>
						<div class="form-item">
							<div class="form-label">转账金额</div>
							<div class="form-value">
								<input type="number" min="0.00" step="0.01" name="amount" id="amount" required  lay-verify="amount" lay-verType="tips" oninput="if(value.length>10)value=value.slice(0,10)" placeholder="0.00">
								<span class="big-write-show" id="amountShowBig"></span>
							</div>
						</div>
						<div class="form-item">
							<div class="form-label">用途/备注</div>
							<div class="form-value">
								<input type="text" name="remark" required  lay-verify="required" lay-verType="tips" placeholder="输入或点击右侧选择">
								#for(uses: usesList)
								<a href="javascript:void(0);" onclick ="selectUses('#(uses.name)')">#(uses.name)</a>
								#end
							</div>
						</div>


						#if(feePre!=null)
						<p>
						<a style="font-size: 14px" href="javascript:void(0);">注意：转账到他人银行卡(对私):1000元需要收取#(feePre)元的手续费,以此类推。</a>
						</p>
						<br>
						#end

						#if(feeCom!=null)
						<p>
						<a style="font-size: 14px" href="javascript:void(0);">注意：转账到他人银行卡(对公):1000元需要收取#(feePre)元的手续费,以此类推。</a>
						</p>
						#end



						<div class="form-item">
							<div class="form-label"></div>
							<div class="form-value"><button class="jui-btn jui-btn-blue" lay-submit lay-filter="order-form-submit">下一步</button></div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>

	#include("common/footer.html")
<script src="/static/jquery/1.11.0/jquery.min.js"></script>
<script src="/static/layui/layui.js"></script>
<script>
layui.config({
	base: '/static/fly/mods/'
}).extend({
	fly: 'index'
}).use(['layer', 'form', 'fly', 'layarea'], function(){
	var $ = layui.$, layer = layui.layer, form = layui.form, fly = layui.fly,layarea = layui.layarea;
	// 数字转中文大写
	$("#amount").bind("input",function(event){
		var money = this.value;
		var big = fly.convertCurrency(money)
		$("#amountShowBig").html(big);
	});
	// 表单验证
	form.verify({
		amount: function(value, item){
    		if(!/^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/.test(value)){
    			return "请输入正确的金额";
    		}
    	}
	});
	// 订单表单提交（下一步按钮）
	form.on("submit(order-form-submit)", function(data){
		$("#safe-validate input[name='contactsId']").val($("div.content select[name='contactsId']").val());
		$("#safe-validate input[name='amount']").val($("div.content input[name='amount']").val());
		$("#safe-validate input[name='remark']").val($("div.content input[name='remark']").val());
		$("#description").html("您即将给<span>" + $("select[name='contactsId'] :selected").text()
				+ "</span>转账<span class='money'>" + $("div.content input[name='amount']").val()
				+ "</span>元，用途为<span>"+ $("div.content input[name='remark']").val()
				+ "</span>，是否确定？");
		if($("div.content input[name='amount']").val()<100000){
			$("#safe-validate div.sms").hide();
		}else{
			$("#safe-validate div.sms").show();
		}
		layer.open({
			type: 1,
			title: "确认提示",
			area: "560px",
			icon: "0",
			btn: ["确 定", "取 消"],
			content:$("#safe-validate"),
			yes: function(index, layero){
				if(layui.cache.checked) {
					$("#safe-validate input[type='submit']").click();
				} else {
					data.field.payPassword = $("#safe-validate input[name='payPassword']").val();
					data.field.smscode = $("#safe-validate input[name='smscode']").val();
					$.post("/customer/home/preview?check", data.field, function(res){
						if(res.code == 0) {
							layui.cache.checked = true;
							$("#safe-validate input[type='submit']").click();
						}else{
							layer.msg(res.msg);
						}
					});
				}
			},
			btn2:  function(index, layero){
				layer.closeAll();
			}
		});
		return false;
	});





    // 添加按钮：银行
    $("#btn-add-bankcard").on("click", function(){
        $("#win-bankcard-edit form")[0].reset();
        layer.open({
            type: 1,
            title: "添加银行卡账户",
            content: $("#win-bankcard-edit"),
            area: "60%",
            btn: ["确 定"],
            yes: function(index, layero){
                layero.contents().find("form input[type='button']").click();
            },
            end: function () {
				console.log("关闭了 layui.open!!!");
                $("#win-bankcard-edit").val("style", "display:none;");
                $("#win-bankcard-edit").hide();
            }
        });
    });
    // 添加按钮：钱包
    $("#btn-add-wallet").on("click", function(){
        $("#win-wallet-edit form")[0].reset();
        layer.open({
            type: 1,
            title: "添加钱包账户",
            content: $("#win-wallet-edit"),
            area: "60%",
            btn: ["确 定"],
            yes: function(index, layero){
                layero.contents().find("form input[type='button']").click();
            },
			end: function () {
                $("#win-wallet-edit").hide();
            }
        });
    });
    // 超链接：编辑
    $("table.list a.edit").on("click", function(e){
        $.ajax({
            url: "/customer/contacts/find",
            type:"get",
            data: {id: $(e.target).attr("dataId"), _r: Math.random()},
            success: function(res){
                if(res.accountType=="wallet"){
                    form.val("win-wallet-edit", res);
                    layer.open({
                        type: 1,
                        title: "修改钱包账户",
                        content: $("#win-wallet-edit"),
                        area: "60%",
                        btn: ["确 定"],
                        yes: function(index, layero){
                            layero.contents().find("form input[type='button']").click();
                        }
                    });
                }else if(res.accountType=="bankCard"){
                    res.isSelf = res.isSelf ? "1" : "0";
                    res.isCompany = res.isCompany ? "1" : "0";
                    form.val("win-bankcard-edit", res);
                    form.render();
                    layarea.render({
                        elem: '#area-picker',
                        data: {province: res.province, city:res.city},
                        change: function (res) {
                            console.log(res);
                        }
                    });

                    layer.open({
                        type: 1,
                        title: "修改银行卡账户",
                        content: $("#win-bankcard-edit"),
                        area: ["80%", "90%"],
                        btn: ["确 定"],
                        yes: function(index, layero){
                            layero.contents().find("form input[type='button']").click();
                        }
                    });
                }else{
                    layer.msg("无法处理的账户：" + res.accountType);
                }

            },
            error: function(xhr){layer.msg("出错了" + xhr);}
        });
    });
    // 超链接：删除
    $("table.list a.del").on("click", function(e){
        layer.confirm('确定要删除['+$(e.target).parents('tr').children('td').first().text()+']吗？', {icon: 3, title:'提示'}, function(index){
            $.ajax({
                url: "/customer/contacts/delete",
                type:"post",
                data: {id: $(e.target).attr("dataId")},
                success: function(res){
                    if(res.code !== 0){
                        layer.msg(res.msg, {icon: 2});
                    }else{
                        layer.msg("删除成功", {icon: 1});
                        layer.closeAll();
                        location.reload();
                    }
                },
                error: function(xhr){layer.msg("出错了" + xhr);}
            });
            layer.close(index);
        });
    });
    // 表单提交
    form.on('submit(layuiadmin-app-form-submit)', function(data){
        var field = data.field; //获取提交的字段
        console.log(field);
        $.ajax({
            url: "/customer/contacts/save",
            type:"post",
            data: field,
            success: function(res){
                if(res.code !== 0){
                    layer.msg(res.msg, {icon: 2});
                }else{
                    layer.msg("添加成功", {icon: 1});
                    layer.closeAll();
                    location.reload();
                }
            },
            error: function(xhr){layer.msg("出错了" + xhr);}
        });
    });
    // 输入卡号匹配银行
    $("#win-bankcard-edit input[name='accountNo']").on("input", function(e){
        var cardNo = $("#win-bankcard-edit input[name='accountNo']").val();
        if(cardNo=="") {
            $("#bank").val("");
            form.render('select');
            //$("#bankLogo").attr("src", "/static/customer/img/banks/DEFAULT.png");
            return;
        }
        if(cardNo.length < 4) {
            return;
        }
        $.get("/customer/contacts/cardbin",{'cardNo':cardNo, 'r':Math.random()}, function(resp) {
            console.log(resp);
            if (resp != null) {
                $("#bankName").val(resp.bankName);
                form.render('select');
                //$("#bankLogo").attr("src", "/static/customer/img/banks/" + resp.banknick + ".png");
            }
        });
    });
    // 省市联动
    layarea.render({
        elem: '#area-picker',
        change: function (res) {
            console.log(res);
        }
    });

    $("input[name='accountNo']").on("input",function () {
        var accountNo = $(this).val();
        if(accountNo.length == 6){
            $.get("/customer/contacts/findMerch",{'accountNo':accountNo, 'r':Math.random()}, function(resp) {
                console.log(resp);
                if (resp != null) {
                    $("input[name='accountName']").val(resp.name);
                    if($("input[name='alias']").val().length == 0){
                        $("input[name='alias']").val(resp.name);
                    }
                }
            });
        }
    })


});
/* 选择用途 */
function selectUses(val) {
	$("input[name='remark']").val(val);
}
/* 发送短信验证码 */
var timer,second=60,flag = false;
function sendsms(){
	if(flag)return;
	flag = true;
	$.post("/customer/home/sendsms/transfer", {amount: $("#amount").val()}, function(data){
		// 验证码发送失败
		if(data.code != 0) {
			flag=false;
    		layer.msg(data.msg, {icon:5});
    		return;
		}
		layer.msg(data.msg, {icon:6});
		// 验证码发送成功
		timer = setInterval(() => {
    		if(second <= 0) {
    			clearInterval(timer);
    			second = 60;
    			flag = false;
    			$("#safe-validate .layui-input-block a").text("获取");
    		} else{
    			$("#safe-validate .layui-input-block a").text(second);
    			second = second - 1;
    		}
    	}, 1000);
	});
}
</script>
<div id="safe-validate">
	<div id="description">
	您即将给***转账**.**元，用途为***，是否确定？
	</div>
	<form class="layui-form" lay-filter="safe-validate" action="/customer/home/preview" method="post">
		<input type="hidden" name="contactsId" value="">
		<input type="hidden" name="amount" value="">
		<input type="hidden" name="remark" value="">
		<input type="hidden" name="tradeType" value="transfer">
		<div class="layui-form-item">
			<label class="layui-form-label">支付密码</label>
			<div class="layui-input-block">
				<input type="password" name="payPassword" maxlength="30" required  lay-verify="required" placeholder="支付密码" autocomplete="off" class="layui-input">
			</div>
		</div>

		<div class="layui-form-item sms">
			<label class="layui-form-label">短信验证码</label>
			<div class="layui-input-block">
				<input type="text" name="smscode" maxlength="30" placeholder="短信验证码" autocomplete="off" class="layui-input">
				<a href="javascript:sendsms()">获取</a>
			</div>
		</div>

		<div class="layui-form-item layui-hide">
			<input type="submit" lay-submit lay-filter="wallet-form-submit" value="隐藏按钮2">
		</div>
	</form>
</div>
	#include("common/addcontacts.html")
</body>
</html>
